Trò chơi Angry Birds trong UNITY Engine
31.697 lượt xem;
1 using System;
2 using UnityEngine;
3
4
5 public class GoEaseElastic
6 {
7 public static float EaseIn( float t, float b, float c, float d )
8 {
9 if( t == 0 )
10 {
11 return b;
12 }
13 if( ( t /= d ) == 1 )
14 {
15 return b + c;
16 }
17 float p = d * .3f;
18 float s = p / 4;
19 return -(float)( c * Math.Pow( 2, 10 * ( t -= 1 ) ) * Math.Sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) ) + b;
20 }
21
22 public static float EaseOut( float t, float b, float c, float d )
23 {
24 if( t == 0 )
25 {
26 return b;
27 }
28 if( ( t /= d ) == 1 )
29 {
30 return b + c;
31 }
32 float p = d * .3f;
33 float s = p / 4;
34 return (float)( c * Math.Pow( 2, -10 * t ) * Math.Sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) + c + b );
35 }
36
37 public static float EaseInOut( float t, float b, float c, float d )
38 {
39 if( t == 0 )
40 {
41 return b;
42 }
43 if( ( t /= d / 2 ) == 2 )
44 {
45 return b + c;
46 }
47 float p = d * ( .3f * 1.5f );
48 float a = c;
49 float s = p / 4;
50 if( t < 1 )
51 {
52 return -.5f * (float)( a * Math.Pow( 2, 10 * ( t -= 1 ) ) * Math.Sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) ) + b;
53 }
54 return (float)( a * Math.Pow( 2, -10 * ( t -= 1 ) ) * Math.Sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) * .5 + c + b );
55 }
56
57 public static float Punch( float t, float b, float c, float d )
58 {
59 if( t == 0 )
60 return 0;
61
62 if( ( t /= d ) == 1 )
63 return 0;
64
65 const float p = 0.3f;
66 return ( c * Mathf.Pow( 2, -10 * t ) * Mathf.Sin( t * ( 2 * Mathf.PI ) / p ) );
67 }
68 }
2 using UnityEngine;
3
4
5 public class GoEaseElastic
6 {
7 public static float EaseIn( float t, float b, float c, float d )
8 {
9 if( t == 0 )
10 {
11 return b;
12 }
13 if( ( t /= d ) == 1 )
14 {
15 return b + c;
16 }
17 float p = d * .3f;
18 float s = p / 4;
19 return -(float)( c * Math.Pow( 2, 10 * ( t -= 1 ) ) * Math.Sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) ) + b;
20 }
21
22 public static float EaseOut( float t, float b, float c, float d )
23 {
24 if( t == 0 )
25 {
26 return b;
27 }
28 if( ( t /= d ) == 1 )
29 {
30 return b + c;
31 }
32 float p = d * .3f;
33 float s = p / 4;
34 return (float)( c * Math.Pow( 2, -10 * t ) * Math.Sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) + c + b );
35 }
36
37 public static float EaseInOut( float t, float b, float c, float d )
38 {
39 if( t == 0 )
40 {
41 return b;
42 }
43 if( ( t /= d / 2 ) == 2 )
44 {
45 return b + c;
46 }
47 float p = d * ( .3f * 1.5f );
48 float a = c;
49 float s = p / 4;
50 if( t < 1 )
51 {
52 return -.5f * (float)( a * Math.Pow( 2, 10 * ( t -= 1 ) ) * Math.Sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) ) + b;
53 }
54 return (float)( a * Math.Pow( 2, -10 * ( t -= 1 ) ) * Math.Sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) * .5 + c + b );
55 }
56
57 public static float Punch( float t, float b, float c, float d )
58 {
59 if( t == 0 )
60 return 0;
61
62 if( ( t /= d ) == 1 )
63 return 0;
64
65 const float p = 0.3f;
66 return ( c * Mathf.Pow( 2, -10 * t ) * Mathf.Sin( t * ( 2 * Mathf.PI ) / p ) );
67 }
68 }